//-----------------------------------------------------------------------
// <copyright file="a_ListStateDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_ListStateDAOBase
    {
        #region Common methods
        public virtual a_ListState Createa_ListStateFromReader(IDataReader reader)
        {
            a_ListState item = new a_ListState();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("FtStateID"))) item.FtStateID = (int)reader["FtStateID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SessionID"))) item.SessionID = (string)reader["SessionID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatType"))) item.CatType = (string)reader["CatType"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID"))) item.CatID = (string)reader["CatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatID"))) item.SubCatID = (string)reader["SubCatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2ID"))) item.SubCat2ID = (string)reader["SubCat2ID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Brand"))) item.Brand = (string)reader["Brand"];
                if (!reader.IsDBNull(reader.GetOrdinal("StrSearch"))) item.StrSearch = (string)reader["StrSearch"];
                if (!reader.IsDBNull(reader.GetOrdinal("HasFilter"))) item.HasFilter = (string)reader["HasFilter"];
                if (!reader.IsDBNull(reader.GetOrdinal("StrSQL"))) item.StrSQL = (string)reader["StrSQL"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtSortBy"))) item.FtSortBy = (string)reader["FtSortBy"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtSortOrder"))) item.FtSortOrder = (string)reader["FtSortOrder"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtBrandID"))) item.FtBrandID = (string)reader["FtBrandID"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtKeyword"))) item.FtKeyword = (string)reader["FtKeyword"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtShowInstockOnly"))) item.FtShowInstockOnly = (string)reader["FtShowInstockOnly"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtColors"))) item.FtColors = (string)reader["FtColors"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtSizes"))) item.FtSizes = (string)reader["FtSizes"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtCustom1"))) item.FtCustom1 = (string)reader["FtCustom1"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtCustom2"))) item.FtCustom2 = (string)reader["FtCustom2"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtCustom3"))) item.FtCustom3 = (string)reader["FtCustom3"];
                if (!reader.IsDBNull(reader.GetOrdinal("FtCustom4"))) item.FtCustom4 = (string)reader["FtCustom4"];
                if (!reader.IsDBNull(reader.GetOrdinal("CurPgNum"))) item.CurPgNum = (string)reader["CurPgNum"];
                if (!reader.IsDBNull(reader.GetOrdinal("City"))) item.City = (string)reader["City"];
                if (!reader.IsDBNull(reader.GetOrdinal("State"))) item.State = (string)reader["State"];
                if (!reader.IsDBNull(reader.GetOrdinal("Zipcode"))) item.Zipcode = (string)reader["Zipcode"];
                if (!reader.IsDBNull(reader.GetOrdinal("Country"))) item.Country = (string)reader["Country"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("StoreID"))) item.StoreID = (int)reader["StoreID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID2"))) item.CatID2 = (string)reader["CatID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCatID2"))) item.SubCatID2 = (string)reader["SubCatID2"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubCat2ID2"))) item.SubCat2ID2 = (string)reader["SubCat2ID2"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_ListState methods
            
        public virtual void Createa_ListState(a_ListState a_ListState)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_ListState_ins");
                
                database.AddInParameter(dbCommand, "@SessionID", DbType.AnsiString, a_ListState.SessionID);
                database.AddInParameter(dbCommand, "@CatType", DbType.AnsiString, a_ListState.CatType);
                database.AddInParameter(dbCommand, "@CatID", DbType.AnsiString, a_ListState.CatID);
                database.AddInParameter(dbCommand, "@SubCatID", DbType.AnsiString, a_ListState.SubCatID);
                database.AddInParameter(dbCommand, "@SubCat2ID", DbType.AnsiString, a_ListState.SubCat2ID);
                database.AddInParameter(dbCommand, "@Brand", DbType.AnsiString, a_ListState.Brand);
                database.AddInParameter(dbCommand, "@StrSearch", DbType.AnsiString, a_ListState.StrSearch);
                database.AddInParameter(dbCommand, "@HasFilter", DbType.AnsiString, a_ListState.HasFilter);
                database.AddInParameter(dbCommand, "@StrSQL", DbType.AnsiString, a_ListState.StrSQL);
                database.AddInParameter(dbCommand, "@FtSortBy", DbType.AnsiString, a_ListState.FtSortBy);
                database.AddInParameter(dbCommand, "@FtSortOrder", DbType.AnsiString, a_ListState.FtSortOrder);
                database.AddInParameter(dbCommand, "@FtBrandID", DbType.AnsiString, a_ListState.FtBrandID);
                database.AddInParameter(dbCommand, "@FtKeyword", DbType.AnsiString, a_ListState.FtKeyword);
                database.AddInParameter(dbCommand, "@FtShowInstockOnly", DbType.AnsiString, a_ListState.FtShowInstockOnly);
                database.AddInParameter(dbCommand, "@FtColors", DbType.AnsiString, a_ListState.FtColors);
                database.AddInParameter(dbCommand, "@FtSizes", DbType.AnsiString, a_ListState.FtSizes);
                database.AddInParameter(dbCommand, "@FtCustom1", DbType.AnsiString, a_ListState.FtCustom1);
                database.AddInParameter(dbCommand, "@FtCustom2", DbType.AnsiString, a_ListState.FtCustom2);
                database.AddInParameter(dbCommand, "@FtCustom3", DbType.AnsiString, a_ListState.FtCustom3);
                database.AddInParameter(dbCommand, "@FtCustom4", DbType.AnsiString, a_ListState.FtCustom4);
                database.AddInParameter(dbCommand, "@CurPgNum", DbType.AnsiString, a_ListState.CurPgNum);
                database.AddInParameter(dbCommand, "@City", DbType.AnsiString, a_ListState.City);
                database.AddInParameter(dbCommand, "@State", DbType.AnsiStringFixedLength, a_ListState.State);
                database.AddInParameter(dbCommand, "@Zipcode", DbType.AnsiString, a_ListState.Zipcode);
                database.AddInParameter(dbCommand, "@Country", DbType.AnsiStringFixedLength, a_ListState.Country);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_ListState.DomainID);
                database.AddInParameter(dbCommand, "@StoreID", DbType.Int32, a_ListState.StoreID);
                database.AddInParameter(dbCommand, "@CatID2", DbType.AnsiString, a_ListState.CatID2);
                database.AddInParameter(dbCommand, "@SubCatID2", DbType.AnsiString, a_ListState.SubCatID2);
                database.AddInParameter(dbCommand, "@SubCat2ID2", DbType.AnsiString, a_ListState.SubCat2ID2);
                database.AddOutParameter(dbCommand, "@FtStateID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_ListState.FtStateID = (int)database.GetParameterValue(dbCommand, "@FtStateID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_ListState methods
        
        public virtual void Updatea_ListState(a_ListState a_ListState)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_ListState_upd");            
                
                database.AddInParameter(dbCommand, "@FtStateID", DbType.Int32, a_ListState.FtStateID);
                database.AddInParameter(dbCommand, "@SessionID", DbType.AnsiString, a_ListState.SessionID);
                database.AddInParameter(dbCommand, "@CatType", DbType.AnsiString, a_ListState.CatType);
                database.AddInParameter(dbCommand, "@CatID", DbType.AnsiString, a_ListState.CatID);
                database.AddInParameter(dbCommand, "@SubCatID", DbType.AnsiString, a_ListState.SubCatID);
                database.AddInParameter(dbCommand, "@SubCat2ID", DbType.AnsiString, a_ListState.SubCat2ID);
                database.AddInParameter(dbCommand, "@Brand", DbType.AnsiString, a_ListState.Brand);
                database.AddInParameter(dbCommand, "@StrSearch", DbType.AnsiString, a_ListState.StrSearch);
                database.AddInParameter(dbCommand, "@HasFilter", DbType.AnsiString, a_ListState.HasFilter);
                database.AddInParameter(dbCommand, "@StrSQL", DbType.AnsiString, a_ListState.StrSQL);
                database.AddInParameter(dbCommand, "@FtSortBy", DbType.AnsiString, a_ListState.FtSortBy);
                database.AddInParameter(dbCommand, "@FtSortOrder", DbType.AnsiString, a_ListState.FtSortOrder);
                database.AddInParameter(dbCommand, "@FtBrandID", DbType.AnsiString, a_ListState.FtBrandID);
                database.AddInParameter(dbCommand, "@FtKeyword", DbType.AnsiString, a_ListState.FtKeyword);
                database.AddInParameter(dbCommand, "@FtShowInstockOnly", DbType.AnsiString, a_ListState.FtShowInstockOnly);
                database.AddInParameter(dbCommand, "@FtColors", DbType.AnsiString, a_ListState.FtColors);
                database.AddInParameter(dbCommand, "@FtSizes", DbType.AnsiString, a_ListState.FtSizes);
                database.AddInParameter(dbCommand, "@FtCustom1", DbType.AnsiString, a_ListState.FtCustom1);
                database.AddInParameter(dbCommand, "@FtCustom2", DbType.AnsiString, a_ListState.FtCustom2);
                database.AddInParameter(dbCommand, "@FtCustom3", DbType.AnsiString, a_ListState.FtCustom3);
                database.AddInParameter(dbCommand, "@FtCustom4", DbType.AnsiString, a_ListState.FtCustom4);
                database.AddInParameter(dbCommand, "@CurPgNum", DbType.AnsiString, a_ListState.CurPgNum);
                database.AddInParameter(dbCommand, "@City", DbType.AnsiString, a_ListState.City);
                database.AddInParameter(dbCommand, "@State", DbType.AnsiStringFixedLength, a_ListState.State);
                database.AddInParameter(dbCommand, "@Zipcode", DbType.AnsiString, a_ListState.Zipcode);
                database.AddInParameter(dbCommand, "@Country", DbType.AnsiStringFixedLength, a_ListState.Country);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_ListState.DomainID);
                database.AddInParameter(dbCommand, "@StoreID", DbType.Int32, a_ListState.StoreID);
                database.AddInParameter(dbCommand, "@CatID2", DbType.AnsiString, a_ListState.CatID2);
                database.AddInParameter(dbCommand, "@SubCatID2", DbType.AnsiString, a_ListState.SubCatID2);
                database.AddInParameter(dbCommand, "@SubCat2ID2", DbType.AnsiString, a_ListState.SubCat2ID2);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_ListState methods
        public virtual void Deletea_ListState(int ftStateID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_ListState_del");
                
                database.AddInParameter(dbCommand, "@FtStateID", DbType.Int32, ftStateID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_ListState methods
        
        public virtual a_ListState Geta_ListState(int ftStateID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_ListState_sel");
                
                database.AddInParameter(dbCommand, "@FtStateID", DbType.Int32, ftStateID);
                
                a_ListState a_ListState =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_ListState = Createa_ListStateFromReader(reader);
                        reader.Close();
                    }
                }
                return a_ListState;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_ListStateList methods
        public virtual a_ListStateCollection Geta_ListStateList(a_ListStateColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_ListState_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_ListStateCollection a_ListStateCollection = new a_ListStateCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_ListState a_ListState = Createa_ListStateFromReader(reader);
                        a_ListStateCollection.Add(a_ListState);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_ListStateCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_ListStateCollection Geta_ListStateList(a_ListStateColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_ListStateList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}